<?php


class CommentController extends Controller
{

	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
			'postOnly + Support,update', // we only allow deletion via POST request
		);
	}

	public function actionList($id,$page=1)
	{
		$pagesize=Yii::app()->params["comment_pagesize"];
		$criteria = new CDbCriteria;
		$criteria->compare('parentid', $id);
		$criteria->order ="createtime desc";
		$criteria->limit=$pagesize;
		$criteria->offset= ($page-1)*$pagesize;
		$list= Comment::model()->findAll($criteria);
		echo CJSON::encode(array('status'=>200,'result'=>$list));
	}


	public function actionSupport()
	{
		if (isset($_POST['id'])) {
			$sql ="update edu_comment set Supports=Supports+1 where id=:id";
			Yii::app()->db->createCommand($sql)->bindParam(":id",$_POST['id'])->execute();
		}
		echo CJSON::encode(array('status'=>200,'result'=>'','message'=>'操作成功'));
	}

	public function actionOpposition()
	{
		if (isset($_POST['id'])) {
			$sql ="update edu_comment set opposition=opposition+1 where id=:id";
			Yii::app()->db->createCommand($sql)->bindParam(":id",$_POST['id'])->execute();
		}
		echo CJSON::encode(array('status'=>200,'result'=>'','message'=>'操作成功'));
	}
}

?>